package com.cxhome.cxinfox.QCellCore;

import java.util.List;

import org.apache.log4j.Logger;

import com.jfinal.aop.Clear;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import com.traffic.managent.base.BaseService;
import com.traffic.managent.util.StringUtils;

/**
 * 地市获取
 * 
 */
public class PhoneHeadService extends BaseService {

	private final static Logger log = Logger.getLogger(PhoneHeadService.class);
	public static final PhoneHeadService service = new PhoneHeadService();

	/**
	 * 
	 * 地市下拉框
	 * 
	 * @return
	 */
	@Clear
	public String selectArea(String pvovince, String selected) {

		String sql = "select areaCode, cityName,province from cx_phone_head where 1=1 ";

		if (StringUtils.isNotEmpty(pvovince)) {
			sql += " and province = '" + pvovince + "'";
		}
		sql += "group by areaCode ";

		List<Record> list = Db.find(sql);

		StringBuffer sb = new StringBuffer("");

		if (list != null && list.size() > 0) {
			// <option value="010">北京</option>
			for (Record phonehead : list) {
				sb.append("<option value=\"");
				sb.append(phonehead.getStr("areaCode"));
				sb.append("\" ");
				sb.append(" name=\"");
				sb.append(phonehead.getStr("province"));
				sb.append("\" ");
				sb.append((selected != null && phonehead.getStr("areaCode").equals(selected)) ? "selected" : "");
				sb.append(">");
				sb.append(phonehead.getStr("cityName"));
				sb.append("</option>");
			}
		}
		return sb.toString();
	}

}
